#include <stdio.h>
#include <math.h>
float getNAN();
float Abs(float);
#define MY_FLOAT_MIN 0.0000000000000000000000000000000000000000000014012984643248170709237295832899161312802619418765157718f
#define MY_FLOAT_MAX  340282346638528859811704183484516925440.000000f
#define MY_FLOAT_MIN -340282346638528859811704183484516925440.000000f

int main()
{
  float nan = -getNAN();
  float f = 1.0;
  float k = 2.0;
  while(1==1)
    {
	 float oldf=f;
	 f-=Abs(k*f);
	 if (f==oldf)
	   {
		printf("f is stuck %f \n",f);
		k*=.5;
	   }
	 if(f==nan)
	   {
		printf("f is nan \n");
		k*=.5;
		printf("k is nan %4.100f \n",k);
		f=oldf;		
	   }
	 if (k == 0)
	   {
		printf ("k is 0 \n");
		printf("%f \n",f);
		return (0);
	   }
 	 printf(":( %f \n",f);
    }
}

float Abs(float f)
{
  return  (f >= 0) ? f : -f;
}

/*** return NAN ***/
float getNAN()
{
  float n = 1.0;
  for (int i =0; i<149; i++)
    {
	 printf("iterating %f \n", n);
      n*=2;
    }
  return n;
} 
